#ifndef __MARS_GRAPHICS_SHADER_PARAMETER_SLOT_H__
#define __MARS_GRAPHICS_SHADER_PARAMETER_SLOT_H__

#include "MarsObject.h"
#include "MarsType.h"

namespace Graphics
{

class VRamBuffer;

class ShaderParameterSlot : public Core::Object
{
public:
									ShaderParameterSlot( Core::uint32 iSlotId, Core::uint32 iBufferSize );
									~ShaderParameterSlot();

	Core::uint32							GetBufferSize() const;
	void*							GetUserData() const;
	Core::uint32							GetSlotId() const;
	VRamBuffer*						GetVRamBuffer() const;

	void							SetUserData( Core::uint32 iOffset, Core::uint32 iSize, void* pUserData );
	void							SetVRamBuffer( VRamBuffer* pVRamBuffer );

private:
	Core::uint32							m_iSlotId;
	Core::uint32							m_iBufferSize;
	void*							m_pBuffer;
	VRamBuffer*						m_pVRamBuffer;
};

inline ShaderParameterSlot::ShaderParameterSlot( Core::uint32 iSlotId, Core::uint32 iBufferSize )
	: m_iSlotId( iSlotId )
	, m_iBufferSize( iBufferSize )
	, m_pVRamBuffer( NULL )
{
	m_pBuffer = malloc( m_iBufferSize );
}

inline ShaderParameterSlot::~ShaderParameterSlot()
{
	free( m_pBuffer );
	m_pBuffer = NULL;
}

inline Core::uint32 ShaderParameterSlot::GetBufferSize() const
{
	return m_iBufferSize;
}

inline Core::uint32 ShaderParameterSlot::GetSlotId() const
{
	return m_iSlotId;
}

inline void* ShaderParameterSlot::GetUserData() const
{
	return m_pBuffer;
}

inline VRamBuffer* ShaderParameterSlot::GetVRamBuffer() const
{
	return m_pVRamBuffer;
}

inline void ShaderParameterSlot::SetUserData( Core::uint32 iOffset, Core::uint32 iSize, void* pUserData )
{
	MARS_ASSERT( iOffset >= 0 && iOffset < m_iBufferSize && iOffset + iSize <= m_iBufferSize );
	MARS_MEMCPY( ( ( uint8* )m_pBuffer ) + iOffset, pUserData, iSize );
}

inline void ShaderParameterSlot::SetVRamBuffer( VRamBuffer* pVRamBuffer )
{
	m_pVRamBuffer = pVRamBuffer;
}

} // end of namespace Graphics

#endif // end of #ifndef __MARS_GRAPHICS_SHADER_PARAMETER_SLOT_H__